﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for reviewBUS
/// </summary>
public class reviewBUS
{
    reviewDAL redal;
	public reviewBUS()
	{
        redal = new reviewDAL();
    }
    public DataTable getAllReview() 
    {
        return redal.getReviews();
    }
    public review getReviewByReviewID(int review_id)
    {
        review re = new review() ;
        reviewDAL redal = new reviewDAL();
        DataTable dt = redal.getReviewByReviewID(review_id);
        if(!dt.HasErrors){
            foreach (DataRow dr in dt.Rows)
            {
                 re = new review(
                    Convert.ToInt32(dr["review_id"]),
                    Convert.ToInt32(dr["product_id"]),
                    Convert.ToInt32(dr["customer_id"]),
                    dr["subject"].ToString(),
                    dr["comment"].ToString(),
                    Convert.ToBoolean(dr["status"]),
                    Convert.ToDateTime(dr["date_added"]),
                    Convert.ToDateTime(dr["date_modified"])
                );
            }
        }

        return re;
        
    }
    public DataTable getReviewsByStatus(bool status){
        reviewDAL redal = new reviewDAL();
        return redal.getReviewsByStatus(status);
    }
    public bool InsertReview(review re){
        reviewDAL redal = new reviewDAL();
        if (redal.insertReview(re)!=0){
            return true;
        }else{
            return false;
        }
    }
    public bool UpdateReview(review re) 
    {
        reviewDAL redal = new reviewDAL();
        if (redal.updateReview(re) != 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public bool deleteReview(int n)
    {
        if (redal.delete_review(n) != 0) 
        {
            return true;
        }
        return false;
    }
}